<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *售后列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'用户列表'),
);
//售后列表
if($_RQ['op']=='list' || $_RQ['op']=='fromclass'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['status']!='all'){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}else{
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['classid']){
		$params['classid']=intval($_RQ['classid']);
		$return['params']['classid']=$_RQ['classid'];
	}
	if($_RQ['id'] && $_RQ['op']=='fromclass'){
		$params['classid']=intval($_RQ['id']);
		$return['params']['classid']=$_RQ['id'];
		$this->session('classid',$params['classid']);
	}
	if($_RQ['op']=='fromclass'){
		$params['classid']=$this->session('classid');
		$return['params']['classid']=$this->session('classid');
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:10;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$list=pdo_getslice('jy_yxw_yonghu',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('yonghu')->member_show($item['id']);
			if($item['danganimage1'] && $item['danganimage2']){
				$item['isdangan']=1;
			}
			if(!$item['danganimage1'] || !$item['danganimage2']){
				$item['isdangan']=2;
			}
			if(!$item['danganimage1'] && !$item['danganimage2']){
				$item['isdangan']=0;
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export',
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：
		</br>1、这里显示本门店的售后！
		','del_message'=>'确认删除该售后吗？','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'用户信息','type'=>'member'),
			array('name'=>'sn','title'=>'编号','type'=>'string'),
			array('name'=>'classid','title'=>'售后群','type'=>'select','options'=>'class'),
			array('name'=>'fankuigs','title'=>'反馈公司','type'=>'string'),
			array('name'=>'fankuitime','title'=>'反馈时间','type'=>'string'),
			array('type'=>'img_string','title'=>'反馈薪资','data'=>array(
				array('title'=>'试用期：','name'=>'fankuifee1'),
				array('title'=>'转正：','name'=>'fankuifee2')
				)
			),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'日期','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','action'=>'jy_yxw/juese12.list/setfankui','title'=>'添加反馈','show'=>array('status'=>array(13))),
			array('type'=>'modal','action'=>'jy_yxw/juese12.list/setfankui','title'=>'编辑反馈','show'=>array('status'=>array(14,15,16,21,22,23))),
		),'batch'=>$batch),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'手机号','name'=>'mobile','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'售后名称','name'=>'title','help'=>''),
			array('name'=>'status','width'=>'15','title'=>'状态','type'=>'radio','options'=>'status'),
			
			//array('name'=>'storeid','width'=>'15','title'=>'所属门店','type'=>'select','options'=>'stores'),
		),
	);
	if($_RQ['op']!='fromclass'){
		$htmls['search'][]=array('name'=>'classid','width'=>'15','title'=>'售后群','type'=>'select','options'=>'class');
	}
	//$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['class']=$this->getall('class',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['status']=$this->yonghu_status;
	$return['status']['all']='全部';
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='setfankui'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		if($post['status']!=13 && (!$post['fankuigs'] || !$post['fankuitime'])){
			exi('请填写反馈公司，反馈时间！','error');
		}
		pdo_update('jy_yxw_yonghu',array('status'=>$post['status'],'fankuigs'=>$post['fankuigs'],'fankuitime'=>$post['fankuitime'],'fankuifee1'=>$post['fankuifee1'],'fankuifee2'=>$post['fankuifee2']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('操作成功！','','list');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_yonghu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择售后','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'编辑反馈',
	);
	$htmls['edit']=array(
			array('name'=>'status','title'=>'反馈状态','type'=>'radio','options'=>'status'),
			array('name'=>'fankuigs','title'=>'反馈公司','type'=>'string'),
			array('name'=>'fankuitime','title'=>'反馈时间','type'=>'string'),
			array('name'=>'fankuifee1','title'=>'试用期薪资','type'=>'string'),
			array('name'=>'fankuifee2','title'=>'转正薪资','type'=>'string'),
	);
	$return['htmls']=$htmls;
	$return['status']=array(
			13=>'待反馈',
			14=>'已反馈',
			15=>'异常反馈',
			16=>'超期反馈',
			21=>'二次反馈',
			22=>'取消放弃反馈',
			23=>'延迟反馈',
	);
	exi($return);
}
if($_RQ['op']=='export'){
	//售后列表
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['status']!='all'){
		$params['status']=intval($_RQ['status']);
	}
	if($_RQ['classid']){
		$params['classid']=intval($_RQ['classid']);
		$return['params']['classid']=$_RQ['classid'];
	}
	$return['params']['status']=$_RQ['status'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	$list=pdo_getall('jy_yxw_yonghu',$params,$fields);
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
		}
	}
	$header=array(
		'id'=>'售后ID',
		'title'=>'售后姓名',
		'mobile'=>'手机号',
		'mobile2'=>'手机号',
		'createtime'=>'注册时间',
	);
	model('core/tools')->export2excel($header,$list,'售后数据');
}
if($_RQ['op']=='del'){
	exi('不能删除！','error');	
}